<?php
/**
 * Created by PhpStorm.
 * User: sqq
 * Date: 2018/11/12
 * Time: 15:31
 * Description：ahp同步门店信息脚本（上线时候执行一次即可）
 */
$service_path = __DIR__ . "/../../../api/";
ob_start();
require_once($service_path . "public/index.php");
ob_end_clean();

echo date('Y-m-d H:i:s',time())." ahp maintenance shops cancel started \n";

//查询cms门店表中的所有数据
$allShop = MaintenanceShops::all();
if(!is_null($allShop)){
    foreach($allShop as $key => $val){
        $shop = AhpMaintenanceShops::where('cms_shop_id',$val->id)->first();
        if(is_null($shop)){
            $shop = New AhpMaintenanceShops();
            $shop->cms_shop_id = $val->id;
            $shop->status = 1;
            $shop->created_at = Common::currentTimeString();
            $shop->created_by = 1;
        }
        if(is_null($shop->address)){
            $shop->address = $val->address;
        }
        if(is_null($shop->tel_phone)){
            $shop->tel_phone = $val->tel_phone;
        }
        if(is_null($shop->longitude)){
            $shop->longitude = $val->longitude;
        }
        if(is_null($shop->latitude)){
            $shop->latitude = $val->latitude;
        }
        if(is_null($shop->desc)){
            $shop->desc = $val->desc;
        }
        if(is_null($shop->business_start_time)){
            $shop->business_start_time = $val->business_start_time;
        }
        if(is_null($shop->business_end_time)){
            $shop->business_end_time = $val->business_end_time;
        }
        $shop->cms_shop_name = $val->name;
        $shop->cms_status = $val->status;
        $shop->city_id = $val->city_id;
        $shop->updated_at = Common::currentTimeString();
        $shop->updated_by = 1;
        if(!($shop->save())){
            echo date('Y-m-d H:i:s',time())." ahp maintenance shops retry error \n";return;
        }
    }
}

echo date('Y-m-d H:i:s',time())." ahp maintenance shops retry stoped \n";